package com.homedo.odin.solution.controller.pc;

import com.homedo.core.common.base.controller.BaseController;
import com.homedo.core.common.base.dto.Meta;
import com.homedo.core.common.base.dto.ResultData;
import com.homedo.core.common.exception.BizException;
import com.homedo.odin.solution.contract.mng.DictDataResp;
import com.homedo.odin.solution.service.DictDataServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liyi Created by liyi on 2018/5/30.
 */
@Api(description = "字典数据", tags = {"DictData"}, produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/dict_data")
public class DictDataController extends BaseController<DictDataServiceImpl> {

    @ApiOperation(value = "pc通过type和key获取value", notes = "pc通过type和key获取value（首页标题，type为page，key为subhead）", response = DictDataResp.class, httpMethod = "GET")
    @GetMapping
    public ResultData getDictDataByTypeAndKey(
            @ApiParam(value = "字典类型", required = true) @RequestParam("type") String type,
            @ApiParam(value = "字典key", required = true) @RequestParam("key") String key) {
        if (StringUtils.isBlank(type)) {
            throw new BizException(Meta.CODE_451.getCode(), "该类型异常");
        }
        if (StringUtils.isBlank(key)) {
            throw new BizException(Meta.CODE_451.getCode(), "该关键字异常");
        }
        DictDataResp resp = baseService.getPcDictDataByTypeAndKey(type, key);
        return ResultData.newInstance(Meta.CODE_200, resp);
    }

}
